<?php

class FV_NiveauConfianceLogin {
	
	private $levelRequis = null;
	
	public function __construct(){
		$this->levelRequis = 3;
	}
	
	public function getMessage($level){
		
		$error = null;
		
		if($level <= 2){
			$error = 'Complexite insufisante';
		}else if($levelRequis == 3){
			$error = 'Complexite moyenne';
		}else{
			$error = 'Complexite forte';
		}
		
		return $error;
	}
	
	public function isRefuse($level){
		return ($level < $levelRequis);			
	}
	
	/**
	 * Renvoit un entier correspondant au niveau de test.
	 * 
	 * @param String $value
	 * @return int niveau du test.
	 */
	public function test($value){
		
		$strongness = 0;
		
		$regex="/[A-Z]/"; //regular expression
		if (!preg_match($regex,$value)){ 
			$strongness++;				 
		}
		
		$regex="/[a-z]/";		
		if (!preg_match($regex,$value)){ 
			$strongness++;				 
		}
		
		$regex="/[0-9]/";		
		if (!preg_match($regex,$value)){ 
			$strongness++;				 
		}
		
		$regex="/[\W_]/"; //special characters and underscore character
		if (!preg_match($regex,$value)){ 
			$strongness++;			 
		}

		
		return $strongness;
	}
	
}